package com.neusoft.bizcore.web.dto.result;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.neusoft.bizcore.web.exception.UnitedException;

import io.swagger.annotations.ApiModelProperty;

/**
 * description
 *
 * @author sunchf
 * @date 2018年12月10日 上午9:26:51
 */
public class ResultListDTO<T> extends AbstractResultDTO {

    private static final long serialVersionUID = 8756487352760469154L;

    /**
     * the business list data
     */
    @ApiModelProperty(value = "the business list data", position = 1)
    protected List<T> data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty(value = "data", index = 3)
    public List<T> getData() {
        return this.data;
    }

    public void setData(final List<T> data) {
        this.data = data;
    }

    public ResultListDTO() {
    }

    ResultListDTO(final Status status) {
        this.status = status;
    }

    public static <T> ResultListDTO<T> success(final List<T> listData) {
        if (listData == null) {
            throw new UnitedException("NullPointerException. %s", "The formal parameter 'listData' cannot be null");
        }

        final ResultListDTO<T> result = new ResultListDTO<>(Status.success);
        result.setData(listData);
        return result;
    }

    public static <T> ResultListDTO<T> failure(final List<T> listData) {
        final ResultListDTO<T> result = new ResultListDTO<>(Status.failure);
        result.setData(listData);
        return result;
    }
}
